package com.example.bailin.giftsay.guide.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.entity.SpecialEntity;
import com.example.bailin.giftsay.tool.MyApp;
import com.example.bailin.giftsay.tool.NetTool;
import com.squareup.picasso.Picasso;

/**
 * Created by bailin on 16/8/16.
 *
 * 精品页里处理小方块RecyclerView的适配器
 */
public class SpecialAdapter extends RecyclerView.Adapter<SpecialAdapter.SpecialViewHolder> {
    private SpecialEntity specialEntity;

    public void setSpecialEntity(SpecialEntity specialEntity) {
        this.specialEntity = specialEntity;
    }

    @Override
    public SpecialViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(MyApp.getContext())
                .inflate(R.layout.item_selection_special, parent, false);
        SpecialViewHolder viewHolder = new SpecialViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(SpecialViewHolder holder, int position) {
        NetTool tool = new NetTool();
        tool.getImg(specialEntity.getData()
                .getSecondary_banners().get(position).getImage_url(), holder.imageView);
    }

    @Override
    public int getItemCount() {
        return specialEntity.getData().getSecondary_banners() == null ?
                0 : specialEntity.getData().getSecondary_banners().size();
    }

    public class SpecialViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        public SpecialViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.iv_selection_special);
        }
    }
}